package com.googlecode.bip.entity.impl;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.googlecode.bip.entity.ITopic;

/**
 * Bean for a localized topic, default {@link ITopic} implementation
 */
public class Topic
    implements Serializable, ITopic
{
    private static final long serialVersionUID = 2L;

    private int idtopic;    //  key
    private String idlocal; // (key)
    private String name;
    private String description;
    private int parentidtopic;
    private int order;
    private int isactive;

    /**
     * Create a NOT initialized Topic
     */
    public Topic()
    {
        // empty
    }

    /**
     * Create a shadow copy of giving Topic
     *
     * @param o Topic to clone
     */
    public Topic( final Topic o )
    {
        this.idtopic        = o.idtopic;
        this.idlocal        = o.idlocal;
        this.name           = o.name;
        this.description    = o.description;
        this.parentidtopic  = o.parentidtopic;
        this.order          = o.order;
        this.isactive       = o.isactive;
    }

    @Override
    public boolean isIQuestion()
    {
        return false;
    }

    @Override
    public boolean isITopic()
    {
        return true;
    }

    @Override
    public boolean isISurveyMetaData()
    {
        return false;
    }

    /**
     * Initialize Topic from a ResultSet
     * @param rSet Valid ResultSet for a Topic
     * @return this Topic
     * @throws SQLException
     */
    public ITopic set( final ResultSet rSet ) throws SQLException
    {
        idtopic         = rSet.getInt( "idtopic" );
        idlocal         = rSet.getString( "idlocal" );
        name            = rSet.getString( "topicname" );
        description     = rSet.getString( "topicdescription" );
        parentidtopic   = rSet.getInt( "parentidtopic" );
        order           = rSet.getInt( "order" );
        isactive        = rSet.getInt( "isactive" );

        return this;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#getIdTopic()
     */
    @Override
    public int getIdTopic()
    {
        return idtopic;
    }

    /**
     *
     * @param idtopic the idtopic to set
     */
    public void setIdTopic( int idtopic )
    {
        this.idtopic = idtopic;
    }

    @Override
    public String getIdLocal()
    {
        return idlocal;
    }

    @Override
    public void setIdLocal( String idlocal )
    {
        this.idlocal = idlocal;
    }

    @Override
    public String getName()
    {
        return name;
    }

    @Override
    public void setName( final String name )
    {
        this.name = name;
    }

    @Override
    public String getDescription()
    {
        return description;
    }

    @Override
    public void setDescription( final String description )
    {
        this.description = description;
    }

    @Override
    public int getParentIdTopic()
    {
        return parentidtopic;
    }

    @Override
    public void setParentIdTopic( final int parentidtopic )
    {
        this.parentidtopic = parentidtopic;
    }

    @Override
    public int getOrder()
    {
        return order;
    }

    @Override
    public void setOrder( final int order )
    {
        this.order = order;
    }

    @Override
    public int getIsActive()
    {
        return isactive;
    }

    @Override
    public void setIsActive( final int isactive )
    {
        this.isactive = isactive;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        StringBuilder builder = new StringBuilder();

        builder.append("Topic [idtopic=").append(idtopic)
               .append(", idlocal=").append(idlocal)
               .append(", name=").append(name)
               .append(", description=").append(description)
               .append(", parentidtopic=").append(parentidtopic)
               .append(", order=").append(order)
               .append(", isactive=").append(isactive)
               .append("]");

        return builder.toString();
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((description == null) ? 0 : description.hashCode());
        result = prime * result + ((idlocal == null) ? 0 : idlocal.hashCode());
        result = prime * result + idtopic;
        result = prime * result + isactive;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + order;
        result = prime * result + parentidtopic;
        return result;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals( Object obj )
    {
        if( this == obj ) return true;
        if( obj == null ) return false;
        if( getClass() != obj.getClass() ) return false;
        Topic other = (Topic)obj;
        if( description == null ) {
            if( other.description != null ) return false;
        } else if( !description.equals( other.description ) ) return false;
        if( idlocal == null ) {
            if( other.idlocal != null ) return false;
        } else if( !idlocal.equals( other.idlocal ) ) return false;
        if( idtopic != other.idtopic ) return false;
        if( isactive != other.isactive ) return false;
        if( name == null ) {
            if( other.name != null ) return false;
        } else if( !name.equals( other.name ) ) return false;
        if( order != other.order ) return false;
        if( parentidtopic != other.parentidtopic ) return false;
        return true;
    }

}
